


import plotting.*;

Figure fig;

double[] y;
double[] y1;
double[] y2;
double[] x;
int start=0;
int cur=39;
int n=39;

int count = 0;

void setup()  {  
  size(520, 320);
  y=new double[40];
  for (int j=0;j<40;j++) y[j]=random(0.0,1.0)*10+40;
  y1=new double[40];
  for (int j=0;j<40;j++) y1[j]=random(0.0,1.0)*10+40;
  y2=new double[40];
  for (int j=0;j<40;j++) y1[j]=random(0.0,1.0)*10+40;

  x=new double[40];
  for (int j=0;j<40;j++) x[j]=j/10.;
  
  x[cur]=0;
  
  fig=new Figure(this,new Rectangle(60,60,400,200));
  fig.numberFormat = "%3.1f";
  fig.autoScaleX=true;
  fig.autoScaleY=true;
  fig.update();
}

void draw() {

  count++;
  
  if (count<5) {
      MonoLineStatic();
      delay(1000);
  }
  else if (count<10) {
      MonoSignalStatic();
      delay(500);
  }
  else if (count==10) 
  {
    start=0; cur=39; x[cur]=0;
  }
  else if (count<60) {
      MonoSignalRunning();
        delay(50);
  }
  else if (count<110) {
      MonoLineRunning();
      delay(50);
  }
  else if (count==110) 
  {
      fig.gridColor = 0x55333399;
      fig.textColor = 0xFF44FF44;
      fig.axisColor = 0xFF3333FF;
      fig.bgColor = 0xFF000033;
      fig.axisThickness = 2.0f;
      fig.gridThickness = 1.0f;
      fig.tickThickness = 1.0f;
  }
  else if (count<210) {
      ColorMultiLineRunning();
      delay(50);
  }
    else if (count==210) 
  {
      fig.gridColor = 0x55FFFFFF;
      fig.textColor = 0xFFFFFFFF;
      fig.axisColor = 0xFFFFFFFF;
      fig.lineColor = 0xFFFFFFFF;
      fig.bgColor = 0xFF000000;
      fig.axisThickness = 2.0f;
      fig.gridThickness = 1.0f;
      fig.lineThickness = 2.0f;
      fig.tickThickness = 1.0f;
  }
  else count=0;

}

void ColorMultiLineRunning()
{
  y[cur]=random(0.0,1.0)*10+40;
  y1[cur]=random(0.0,1.0)*10+40;
  y2[cur]=random(0.0,1.0)*10+40;
  x[cur]+=4.0;  
  noFill();
  background(0);
  fig.draw();
  fig.lineColor = 0xFF44FF44;
  fig.isFilled=false;
  fig.lineThickness = 4.0f;
  fig.plot(x,y,Figure.Approx.linear,start,n);
  fig.lineColor = 0xFF8888FF;
  fig.isFilled=true;
  fig.lineThickness = 2.0f;
  fig.plot(x,y1,Figure.Approx.linear,start,n);
  fig.lineColor = 0xFFFF8800;
  fig.isFilled=false;
  fig.lineThickness = 1.0f;
  fig.plot(x,y2,Figure.Approx.linear,start,n);
  cur=start;
  start+=1; if (start==40) start=0;
}


void MonoLineRunning()
{
  y[cur]=random(0.0,1.0)*10+40;
  x[cur]+=4.0;  
  noFill();
  background(0);
  fig.draw();
  fig.plot(x,y,Figure.Approx.linear,start,n);
  cur=start;
  start+=1; if (start==40) start=0;
}

void MonoSignalRunning()
{
  y[cur]=random(0.0,1.0)*10+40;
  x[cur]+=4.0;  
  noFill();
  background(0);
  fig.draw();
  fig.plot(y,Figure.Approx.nearest,start,n);
  cur=start;
  start+=1; if (start==40) start=0;
}

void MonoSignalStatic()
{
  for (int j=0;j<40;j++) y[j]=random(0.0,1.0)*10+40;
  noFill();
  background(0);
  fig.draw();
  fig.plot(y,Figure.Approx.nearest);
}

void MonoLineStatic()
{
  for (int j=0;j<40;j++) y[j]=random(0.0,1.0)*10+40;
  for (int j=0;j<40;j++) x[j]=j/10.;
  noFill();
  background(0);
  fig.draw();
  fig.plot(x,y,Figure.Approx.linear);
}


